# cmake_minimum_required(VERSION 3.10)
# project(VideoStreamer)

# set(CMAKE_C_STANDARD 99)

# # 设置交叉编译工具链
# set(CMAKE_SYSTEM_NAME Linux)
# set(CMAKE_SYSTEM_PROCESSOR aarch64)

# # 设置编译器路径
# set(CMAKE_C_COMPILER /home/dazai/hanwei/RK3588L1.03_221025/RK3588/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc)
# set(CMAKE_CXX_COMPILER /home/dazai/hanwei/RK3588L1.03_221025/RK3588/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++)

# # 设置FFmpeg库和头文件路径
# set(FFMPEG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/ffmpeg/include)
# set(FFMPEG_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/ffmpeg/lib)

# include_directories(${FFMPEG_INCLUDE_DIR} include)
# link_directories(${FFMPEG_LIBRARY_DIR})

# set(FFMPEG_LIBRARIES
#     avformat
#     avcodec
#     avutil
#     swscale
#     swresample
#     pthread
# )

# # 设置ZLMediaKit库和头文件路径
# set(ZLMEDIAKIT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/zlmediakit/include)
# set(ZLMEDIAKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/zlmediakit)

# include_directories(${ZLMEDIAKIT_INCLUDE_DIR})
# link_directories(${ZLMEDIAKIT_LIBRARY_DIR})

# set(ZLMEDIAKIT_LIBRARIES
#     mk_api
#     ssl
#     crypto
#     srtp2
#     pthread
#     dl
# )

# # 设置链接器标志
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined")

# # 添加可执行文件
# # add_executable(VideoStreamer
# #     src/main.cpp
# #     src/StreamPusher.cpp
# # )

# # 源文件
# set(SOURCES
#     src/main.c
#     src/video_stream.c
#     src/audio_stream.c
#     src/common.c
#     src/RtspServer.c
#     src/WsServer.c
# )

# # 添加可执行文件
# add_executable(VideoStreamer ${SOURCES})

# # 链接FFmpeg库和ZLMediaKit库
# target_link_libraries(VideoStreamer ${FFMPEG_LIBRARIES} ${ZLMEDIAKIT_LIBRARIES})

# # 设置可执行文件的输出目录
# set(OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../output)

# # 确保输出目录存在
# file(MAKE_DIRECTORY ${OUTPUT_DIRECTORY})

# # 设置目标的输出路径
# set_target_properties(VideoStreamer PROPERTIES
#     RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}
# )


# # ./VideoStreamer -i rtsp://127.0.0.1:554/live/test -o rtsp://127.0.0.1:554/live/c001 -w 1920 -h 1080

cmake_minimum_required(VERSION 3.10)
project(VideoStreamer)

set(CMAKE_C_STANDARD 99)

# 设置交叉编译工具链
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

# 设置编译器路径
set(CMAKE_C_COMPILER /home/dazai/hanwei/RK3588L1.03_221025/RK3588/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /home/dazai/hanwei/RK3588L1.03_221025/RK3588/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/aarch64-none-linux-gnu-g++)

# 设置 FFmpeg 库和头文件路径
set(FFMPEG_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/ffmpeg/include)
set(FFMPEG_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/ffmpeg/lib)

include_directories(${FFMPEG_INCLUDE_DIR} include)
link_directories(${FFMPEG_LIBRARY_DIR})

set(FFMPEG_LIBRARIES
    avformat
    avcodec
    avutil
    swscale
    swresample
    pthread
)

# 设置 ZLMediaKit 库和头文件路径
set(ZLMEDIAKIT_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/zlmediakit/include)
set(ZLMEDIAKIT_LIBRARY_DIR ${CMAKE_SOURCE_DIR}/zlmediakit)

include_directories(${ZLMEDIAKIT_INCLUDE_DIR})
link_directories(${ZLMEDIAKIT_LIBRARY_DIR})

set(ZLMEDIAKIT_LIBRARIES
    mk_api
    ssl
    crypto
    srtp2
    pthread
    dl
)

# 设置链接器标志
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined")

# 源文件
set(SOURCES
    src/main.c
    src/video_stream.c
    src/audio_stream.c
    src/common.c
    src/RtspServer.c
    src/WsServer.c
)

# 添加可执行文件
add_executable(VideoStreamer ${SOURCES})

# 链接 FFmpeg 库和 ZLMediaKit 库
target_link_libraries(VideoStreamer ${FFMPEG_LIBRARIES} ${ZLMEDIAKIT_LIBRARIES})

# 设置可执行文件的输出目录
set(OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../output)

# 确保输出目录存在
file(MAKE_DIRECTORY ${OUTPUT_DIRECTORY})

# 设置目标的输出路径
set_target_properties(VideoStreamer PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}
)
